package com.bwie.house.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.Query;

import com.bwie.house.dao.SubwayDao;
import com.bwie.house.entity.SubwayEntity;
import com.bwie.house.service.SubwayService;


@Service("subwayService")
public class SubwayServiceImpl extends ServiceImpl<SubwayDao, SubwayEntity> implements SubwayService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<SubwayEntity> w = new QueryWrapper<>();
        //获取 省的ID进行精确查找
        String m1 = (String) params.get("m1");
        //获取 市的ID进行精确查找
        String m2 = (String) params.get("m2");
        //获取地铁线路进行模糊查找
        String m3 = (String) params.get("m3");

        //如果省不能与空和空字符串  进行精确查找
        if(StringUtils.isNotEmpty(m1) && m1!=""){
            w.eq("shen_id",m1);
        }
        //如果市不能与空和空字符串  进行精确查找
        if(StringUtils.isNotEmpty(m2) && m2!=""){
            w.eq("shi_id",m2);
        }
        //如果地铁线路进行精确查找  进行模糊查找
        if(StringUtils.isNotEmpty(m3) && m3!=""){
            w.like("subway_line",m3);
        }


        IPage<SubwayEntity> page = this.page(
                new Query<SubwayEntity>().getPage(params),
                w
        );

        return new PageUtils(page);
    }

}